<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/9/18
 * Time: 14:18
 */
namespace Controller;

class MemberController extends TooController{

    //订单列表
    public function order(){
        $order=$this->pdo->pdo_sel("select o.*,m.email as user from s_order as o join s_member as m on o.m_id = m.id order by id desc",2);

        $this->view->assign('order',$order);
        $this->view->display();
    }

    //订单的修改
    public function order_edit(){
        $id=$_GET['id'];
        $type=$_GET['type'];
        if($id&&$type){
            $arr=array();
            $arr['start']=$type;
            if($type==2){
                $arr['pay']='后台支付';
            }else if($type==7){
                $list=$this->pdo->pdo_sel("select * from s_order where id = $id");
                $money=$this->pdo->pdo_sel("select money from s_member where id = '{$list['m_id']}'");
                $money=$money['money']+$list['money'];
                //修改用户余额
                $this->pdo->pdo_upd(array("money"=>$money),"s_member","id = '{$list['m_id']}'");
                //添加记录
                $mo=array();
                $mo['m_id']=$list['m_id'];
                $mo['money']=$list['money'];
                $mo['start']=2;
                $mo['time']=date("Y-m-d H:i:s",time());
                $this->pdo->pdo_ins($mo,'s_money');
            }

            $this->pdo->pdo_upd($arr,'s_order', " id = $id");

            $this->success('操作成功','Member','order');
        }
    }


    //订单删除
    public function order_del(){
        $id=trim($_GET['id'],',');

        if($id){
            //删除数据
            if($this->pdo->pdo_del("s_order"," id in ($id)")){
                $this->retuAjax(array('type'=>1,'msg'=>'删除成功'));
            }
        }
        $this->retuAjax(array('type'=>2,'msg'=>'删除失败'));
    }

    //订单物流处理
    public function order_wl(){
        $id=$_GET['id'];
        $wlh=$_GET['wlh'];
        $wlm=$_GET['wlm'];

        if($id&&$wlh&&$wlm){
            //修改订单物流信息
           if($this->pdo->pdo_upd(array('start'=>3,'wlh'=>$wlh,'wlm'=>$wlm)," s_order "," id = $id")){
               $this->retuAjax(array('msg'=>'操作成功'));
           }
        }
        $this->retuAjax(array('msg'=>'操作失败'));
    }

    //查看物流
    public function order_ckwl(){
        $id=$_GET['id'];
        if($id){
            $order=$this->pdo->pdo_sel("select * from s_order where id = $id");

            //调用物流接口
            $url="http://www.kuaidi100.com/query?type={$order['wlm']}&postid={$order['wlh']}";

            echo file_get_contents($url);
        }
    }
}